sgdk: memory.h File Reference

sgdk

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

Defines | Functions
memory.h File Reference

Memory handling methods. More...

Go to the source code of this file.

## Defines

#define | STACK_SIZE 0x400
#define | MEMORY_HIGH (0x01000000 - STACK_SIZE)
#define | GET_DWORDFROMPBYTE(src) ((src[0] << 24) | (src[1] << 16) | (src[2] << 8) | (src[3] << 0))
#define | GET_DWORDFROMPBYTE_LI(src) ((src[0] << 0) | (src[1] << 8) | (src[2] << 16) | (src[3] << 24))
#define | GET_WORDFROMPBYTE(src) ((src[0] << 8) | (src[1] << 0))
#define | GET_WORDFROMPBYTE_LI(src) ((src[0] << 0) | (src[1] << 8))
#define | GET_DWORDFROMPWORD(src) ((src[0] << 16) | (src[1] << 0))
#define | GET_DWORDFROMPWORD_LI(src) ((src[0] << 0) | (src[1] << 16))
#define | SWAP_u8(x, y)
#define | SWAP_s8(x, y)
#define | SWAP_u16(x, y)
#define | SWAP_s16(x, y)
#define | SWAP_u32(x, y)
#define | SWAP_s32(x, y)

## Functions

void | MEM_init ()
| Initialize memory sub system.
u16 | MEM_getFree ()
| Return available memory in bytes.
void | MEM_free (void *ptr)
| Deallocate space in memory.
void * | MEM_alloc (u16 size)
| Allocate memory block.
void | memset (void *to, u8 value, u16 len)
| Fill block of memory.
void | memsetU16 (u16 *to, u16 value, u16 len)
| Fill block of memory (optimized for u16)
void | memsetU32 (u32 *to, u32 value, u16 len)
| Fill block of memory (optimized for u32)
void | memcpy (void *to, const void *from, u16 len)
| Copy block of memory.
void | memcpyU16 (u16 *to, const u16 *from, u16 len)
void | memcpyU32 (u32 *to, const u32 *from, u16 len)
void | fastMemset (void *to, u8 value, u16 len)
void | fastMemsetU16 (u16 *to, u16 value, u16 len)
void | fastMemsetU32 (u32 *to, u32 value, u16 len)
void | fastMemcpy (void *to, const void *from, u16 len)
void | fastMemcpyU16 (u16 *to, const u16 *from, u16 len)
void | fastMemcpyU32 (u32 *to, const u32 *from, u16 len)

## Detailed Description

Memory handling methods.

Author:
  Stephane Dallongeville

Date:
  08/2011

This unit provides memory copy/set operation and dynamic memory allocation.
Memory organization :
Memory is composed of bloc, the first 2 bytes of a bloc define its size and its state:
b15-b1 = size in number of word (2 bytes)
b0 = used state (1=used, 0=free)
To reach the next bloc you just need to do:
`next_bloc_address = bloc_addres + bloc_size` The end of memory is defined with a 0 sized bloc.

## Define Documentation

#define GET_DWORDFROMPBYTE | ( |  | src | ) | ((src[0] << 24) | (src[1] << 16) | (src[2] << 8) | (src[3] << 0))

Get u32 from u8 array (BigEndian order).

#define GET_DWORDFROMPBYTE_LI | ( |  | src | ) | ((src[0] << 0) | (src[1] << 8) | (src[2] << 16) | (src[3] << 24))

Get u32 from u8 array (LittleEndian order).

#define GET_DWORDFROMPWORD | ( |  | src | ) | ((src[0] << 16) | (src[1] << 0))

Get u32 from u16 array (BigEndian order).

#define GET_DWORDFROMPWORD_LI | ( |  | src | ) | ((src[0] << 0) | (src[1] << 16))

Get u32 from u16 array (LittleEndian order).

#define GET_WORDFROMPBYTE | ( |  | src | ) | ((src[0] << 8) | (src[1] << 0))

Get u16 from u8 array (BigEndian order).

#define GET_WORDFROMPBYTE_LI | ( |  | src | ) | ((src[0] << 0) | (src[1] << 8))

Get u16 from u8 array (LittleEndian order).

#define MEMORY_HIGH (0x01000000 - STACK_SIZE)

Define the memory high address limit for dynamic allocation

#define STACK_SIZE 0x400

Define memory allocated for stack (default = 0x400).

#define SWAP_s16 | ( |  | x,
|  |  | y
| ) |  |

Value:

    {                           \
        s16 swp;                \
                                \
        swp = x;                \
        x = y;                  \
        y = swp;                \
    }

Exchange value of specified s16 variables.

#define SWAP_s32 | ( |  | x,
|  |  | y
| ) |  |

Value:

    {                           \
        s32 swp;                \
                                \
        swp = x;                \
        x = y;                  \
        y = swp;                \
    }

Exchange value of specified s32 variables.

#define SWAP_s8 | ( |  | x,
|  |  | y
| ) |  |

Value:

    {                           \
        s8 swp;                 \
                                \
        swp = x;                \
        x = y;                  \
        y = swp;                \
    }

Exchange value of specified s8 variables.

#define SWAP_u16 | ( |  | x,
|  |  | y
| ) |  |

Value:

    {                           \
        u16 swp;                \
                                \
        swp = x;                \
        x = y;                  \
        y = swp;                \
    }

Exchange value of specified u16 variables.

#define SWAP_u32 | ( |  | x,
|  |  | y
| ) |  |

Value:

    {                           \
        u32 swp;                \
                                \
        swp = x;                \
        x = y;                  \
        y = swp;                \
    }

Exchange value of specified u32 variables.

#define SWAP_u8 | ( |  | x,
|  |  | y
| ) |  |

Value:

    {                           \
        u8 swp;                 \
                                \
        swp = x;                \
        x = y;                  \
        y = swp;                \
    }

Exchange value of specified u8 variables.

## Function Documentation

void fastMemcpy | ( | void * | to,
|  | const void * | from,
|  | u16 | len
| ) |  |

Deprecated:
  Uses memcpy(void *to, const void *from, u16 len) instead.

void fastMemcpyU16 | ( | u16 * | to,
|  | const u16 * | from,
|  | u16 | len
| ) |  |

Deprecated:
  Uses memcpy(void *to, const void *from, u16 len) instead.

void fastMemcpyU32 | ( | u32 * | to,
|  | const u32 * | from,
|  | u16 | len
| ) |  |

Deprecated:
  Uses memcpy(void *to, const void *from, u16 len) instead.

void fastMemset | ( | void * | to,
|  | u8 | value,
|  | u16 | len
| ) |  |

Deprecated:
  Uses memset(void *to, u8 value, u16 len) instead.

void fastMemsetU16 | ( | u16 * | to,
|  | u16 | value,
|  | u16 | len
| ) |  |

Deprecated:
  Uses memsetU16(void *to, u16 value, u16 len) instead.

void fastMemsetU32 | ( | u32 * | to,
|  | u32 | value,
|  | u16 | len
| ) |  |

Deprecated:
  Uses memsetU32(void *to, u32 value, u16 len) instead.

void* MEM_alloc | ( | u16 | size | ) |

Allocate memory block.

Parameters:

  size | Number of bytes to allocate

Returns:
  On success, a pointer to the memory block allocated by the function. The type of this pointer is always void*, which can be cast to the desired type of data pointer in order to be dereferenceable. If the function failed to allocate the requested block of memory (or if specified size = 0), a NULL pointer is returned.

Allocates a block of size bytes of memory, returning a pointer to the beginning of the block. The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.

void MEM_free | ( | void * | ptr | ) |

Deallocate space in memory.

Parameters:

  ptr | Pointer to a memory block previously allocated with Mem_alloc to be deallocated. If a null pointer is passed as argument, no action occurs.

A block of memory previously allocated using a call to Mem_alloc is deallocated, making it available again for further allocations. Notice that this function leaves the value of ptr unchanged, hence it still points to the same (now invalid) location, and not to the null pointer.

void memcpy | ( | void * | to,
|  | const void * | from,
|  | u16 | len
| ) |  |

Copy block of memory.

Parameters:

  to | Pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.
  from | Pointer to the source of data to be copied, type-casted to a pointer of type void*.
  len | Number of bytes to copy.

Copies the values of len long from the location pointed by from directly to the memory block pointed by to. The underlying type of the objects pointed by both the source and destination pointers are irrelevant for this function; The result is a binary copy of the data.

void memcpyU16 | ( | u16 * | to,
|  | const u16 * | from,
|  | u16 | len
| ) |  |

Deprecated:
  Uses memcpy(void *to, const void *from, u16 len) instead.

void memcpyU32 | ( | u32 * | to,
|  | const u32 * | from,
|  | u16 | len
| ) |  |

Deprecated:
  Uses memcpy(void *to, const void *from, u16 len) instead.

void memset | ( | void * | to,
|  | u8 | value,
|  | u16 | len
| ) |  |

Fill block of memory.

Parameters:

  to | Pointer to the block of memory to fill.
  value | Value to be set.
  len | Number of u8 (byte) to be set to the value.

Sets the first num bytes of the block of memory pointed by to with the specified value.

void memsetU16 | ( | u16 * | to,
|  | u16 | value,
|  | u16 | len
| ) |  |

Fill block of memory (optimized for u16)

Parameters:

  to | Pointer to the block of memory to fill.
  value | Value to be set.
  len | Number of (u16) short to be set to the value.

Sets the first num shorts of the block of memory pointed by to with the specified value.

void memsetU32 | ( | u32 * | to,
|  | u32 | value,
|  | u16 | len
| ) |  |

Fill block of memory (optimized for u32)

Parameters:

  to | Pointer to the block of memory to fill.
  value | Value to be set.
  len | Number of u32 (long) to be set to the value.

Sets the first num longs of the block of memory pointed by to with the specified value.

All Classes Files Functions Variables Typedefs Enumerations Defines